//
//  LSDemoViewController.swift
//  LSWeiBo0808
//
//  Created by 李明禄 on 2017/8/12.
//  Copyright © 2017年 SocererGroup. All rights reserved.
//

import UIKit

class LSDemoViewController: LSBaseViewController {
    
    var shutDownBtn: UIButton!

    override func viewDidLoad() {
        super.viewDidLoad()
        
        print("加载了第" + "\(navigationController?.childViewControllers.count ?? 0)" + "控制器")
        title = "第" + "\(navigationController?.childViewControllers.count ?? 0)" + "个"

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    @objc fileprivate func nextVC() {
        let PushVC = LSDemoViewController()
        navigationController?.pushViewController(PushVC, animated: true)
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(true)
        self.shutDownBtn.isHidden = true
    }
    
    override func viewWillAppear (_ animated: Bool) {
        super.viewWillAppear(true)
        shutDownBtn = UIButton.init()
        shutDownBtn.setTitle("关闭", for: .normal)
        shutDownBtn.setTitleColor(UIColor.black, for: .normal)
        //        shutDownBtn.setImage(UIImage.init(named: "compose_guide_icon_close_check"), for: .normal)
        shutDownBtn.frame = CGRect(x: self.view.bounds.width - 120, y: 20, width: 40, height: 40)
        
        shutDownBtn.addTarget(self, action: #selector(shutdown), for: .touchUpInside)
        
        self.naviBar.addSubview(shutDownBtn)
        self.shutDownBtn.isHidden = false
    }

}

extension LSDemoViewController {
    override func setupUI() {
        super.setupUI()        
        self.navItem.rightBarButtonItem = UIBarButtonItem.init(title: "下一个",  normalColor: .black, highlightedColor: .orange, target: self, action: #selector(nextVC), controlEvents: .touchUpInside)
    }
       
    
    
    @objc fileprivate func shutdown() {
        navigationController?.popToViewController((navigationController?.childViewControllers.first)!, animated: true)
    }
}
